package com.baidu.service.impl;

import com.baidu.model.entity.AlbumModel;
import com.baidu.response.ResponseBody;
import com.baidu.service.InAlbumControllerService;
import com.until.pagination.PaginationRequest;
import com.until.response.RestfulCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author user
 */
@Service
public class AlbumControllerServiceImpl implements InAlbumControllerService {
    @Autowired
    private AlbumServiceImpl albumService;

    @Autowired
    private RestfulCode restfulCode;

    @Autowired
    private ResponseBody responseBody;

    /**
     * 添加相册的controller实现
     *
     * @param albumModel 添加的数据
     * @return 返回相应信息
     */
    @Override
    public RestfulCode.CodeSatCode instepAlbumModel(AlbumModel albumModel) {
        Map<String,String> album= new HashMap<>(0);
        RestfulCode.CodeSatCode userActionFailed = null;
        try {
            userActionFailed=responseBody.USER_OPERATION_SUCCEEDED;
            album.put("id",albumService.createAlbumModel(albumModel).getId().toString());
            userActionFailed.setData(album);
        } catch (Exception e) {
            e.printStackTrace();
            userActionFailed=responseBody.INTERNAL_SERVER_ERROR;
        }
        return restfulCode.getFreeResult(userActionFailed);
    }

    /**
     * 得到用户的个人相册 controller 实现
     * @param userid 用户的id
     * @return 返回相应的信息
     */
    @Override
    public RestfulCode.CodeSatCode selectByUserId(Integer userid, PaginationRequest page) {
        RestfulCode.CodeSatCode userActionFailed =responseBody.USER_OPERATION_SUCCEEDED;
        userActionFailed.setData(albumService.selectByUserId(userid,page));
        return restfulCode.getFreeResult(userActionFailed);
    }
}
